package cn.shyouchi.wuguanjia.android.ui.QRCode;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import java.util.Iterator;
import java.util.Set;

import cn.shyouchi.wuguanjia.android.ui.meetting.plan.MeetSignResActivity;
import cn.shyouchi.wuguanjia.android.utils.LogUtil;

/**
 * Created by Eenie on 2017/2/16 at 14:55
 * Email: 472279981@qq.com
 * Des:
 */

public class QRCodeParser {


    private static QRCodeParser mParser;
    Context mContext;
    Uri mUri;

    private QRCodeParser(Context context, String str) {
        this.mContext = context;
        this.mUri = Uri.parse(str);
    }


    public static QRCodeParser instance(Context context, String QRStr) {
        if (mParser == null) {
            synchronized (QRCodeParser.class) {
                if (mParser == null) {
                    mParser = new QRCodeParser(context, QRStr);
                }
            }
        }

        return mParser;
    }

    public void parse() {

        if (mUri.getScheme().equals("meet")) {
            Intent intent = new Intent(mContext, MeetSignResActivity.class);
            Set<String> paramNames = mUri.getQueryParameterNames();
            Iterator<String> iterator = paramNames.iterator();
            while (iterator.hasNext()) {
                String key = iterator.next();
                LogUtil.e(key);

                intent.putExtra(key, mUri.getQueryParameter(key));
            }


            mContext.startActivity(intent);

            LogUtil.e("finish");
        }

    }


}
